#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <math.h>

void parseStr(std::string ist, std::vector<int> &infect_map)
{
    int i = 0;
    while (i < ist.size())
    {
        int pos = ist.find(',', i);
        if (pos != std::string::npos)
        {
            std::string tmp_str = ist.substr(i, pos - i);
            infect_map.push_back(std::stoi(tmp_str));
            i = pos + 1;
        }
        else
        {
            std::string tmp_str = ist.substr(i);
            infect_map.push_back(std::stoi(tmp_str));
            i = ist.size();
        }
    }
}

int main()
{
    std::string ist;
    std::getline(std::cin, ist);

    std::vector<int> infect_map;
    parseStr(ist, infect_map);

    int n = std::sqrt(infect_map.size());

    std::queue<std::pair<int, int>> infect_que;
    for (int i = 0; i < infect_map.size(); i++)
    {
        if (infect_map[i] == 1)
        {
            infect_que.push({i, 0});
        }
    }

    int max_day = -1;
    while (!infect_que.empty())
    {
        auto pr = infect_que.front();
        infect_que.pop();

        if (pr.first + n < infect_map.size())
        {
            if (infect_map[pr.first + n] == 0)
            {
                infect_map[pr.first + n] = 1;
                infect_que.push({pr.first + n, pr.second + 1});
                max_day = std::max(max_day, pr.second + 1);
            }
        }
        if (pr.first - n >= 0)
        {
            if (infect_map[pr.first - n] == 0)
            {
                infect_map[pr.first - n] = 1;
                infect_que.push({pr.first - n, pr.second + 1});
                max_day = std::max(max_day, pr.second + 1);
            }
        }
        if (pr.first + 1 < infect_map.size())
        {
            if (infect_map[pr.first + 1] == 0)
            {
                infect_map[pr.first + 1] = 1;
                infect_que.push({pr.first + 1, pr.second + 1});
                max_day = std::max(max_day, pr.second + 1);
            }
        }
        if (pr.first - 1 < infect_map.size())
        {
            if (infect_map[pr.first - 1] == 0)
            {
                infect_map[pr.first - 1] = 1;
                infect_que.push({pr.first - 1, pr.second + 1});
                max_day = std::max(max_day, pr.second + 1);
            }
        }
    }

    std::cout << max_day << std::endl;
    return 0;
}